<?php

namespace App\Services\Payment;

use App\Services\Login;
use D1M\Payment\Service\OperatorSourceInterface;
use Illuminate\Http\Request;

class OperatorSource implements OperatorSourceInterface
{

    private Login $loginService;

    private Request $request;

    private $data;

    /**
     * @param Login $loginService
     * @param Request $request
     */
    public function __construct(Login $loginService, Request $request)
    {
        $this->loginService = $loginService;
        $this->request = $request;
    }

    /**
     * @inheritDoc
     */
    public function getOperator()
    {
        if ($this->data == null) {
            // 获取 session 数据
            $this->data = $this->loginService->selfCheckToken($this->request);
        }

        return $this->data->login_name;
    }
}